package com.stylefeng.guns.core.util;

import com.github.qcloudsms.*;

import java.util.ArrayList;

public   class TencentSmsUtil {
    private static int appid=1400084152;
    private static  String appKey="df3257382f097f7faa2bd3cf7329366e";
    public static void main(String[] args) throws Exception {
//        ArrayList<String> params=new ArrayList<>();
//        params.add("家具");
//        params.add("鑫合顺望峰路");
//        params.add("17759115277");
//        params.add("望峰路11号");
//        pushSmsToSingleByTemplate("17759115277",110450,params);

        pushVoiceToSingle("17759115277","【鑫合顺】您好，您的奶粉已到网点鑫合顺，请尽快来取。联系电话17759115277。提货地址:望丰路。货物超过三天加收仓储费。配送每票50元起");

    }

    /**
     * 发送短信至单人
     * @param phoneNumber
     * @param msg
     */
    public static SmsSingleSenderResult   pushSmsToSingle(String phoneNumber,String msg){
        try {
            SmsSingleSender sender = new   SmsSingleSender(appid, appKey);
            SmsSingleSenderResult result = sender.send(0, "86", phoneNumber, msg, "", "");
            System.out.print(result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *用制定模板发送短信至单人
     * @param phoneNumber 手机号码
     * @param templateId  模板id
     * @param params 模板中需要填充的字段
     */
    public static SmsSingleSenderResult  pushSmsToSingleByTemplate(String phoneNumber,Integer templateId, ArrayList<String> params){
        try {
        SmsSingleSender sender = new   SmsSingleSender(appid, appKey);
        SmsSingleSenderResult   result = sender.sendWithParam("86", phoneNumber, templateId, params, "", "", "");
        System.out.println(result);
        return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 群发短信至多人
     * @param msg 短信内容
     * @param phoneNumbers 手机号集合
     */
    public static String  pushSmsToMulti(String msg, ArrayList<String> phoneNumbers){
        try {
        SmsMultiSender multiSender = new SmsMultiSender(appid, appKey);
        SmsMultiSenderResult multiSenderResult = multiSender.send(0, "86", phoneNumbers,  msg, "", "");
        System.out.println(multiSenderResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 发送模板短信至多人
     * @param templateId  模板id
     * @param phoneNumbers 手机号码集合
     * @param params 模板需要的参数集合
     */
    public static SmsMultiSenderResult  pushSmsToMultiByTemplate(Integer templateId,  ArrayList<String> phoneNumbers,ArrayList<String>params ){
        try {
            SmsMultiSender multiSender = new SmsMultiSender(appid, appKey);
            SmsMultiSenderResult  multiSenderResult = multiSender.sendWithParam("86", phoneNumbers, templateId, params, "", "", "");
            System.out.println(multiSenderResult);
            return multiSenderResult;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 发送语音至单人
     * @param msg 语音内容
     * @param phoneNumber 电话号码
     */
    public static SmsVoiceVerifyCodeSenderResult  pushVoiceToSingle(String msg, String  phoneNumber) {
        //语音验证码发送
        try {
        SmsVoiceVerifyCodeSender smsVoiceVerifyCodeSender = new SmsVoiceVerifyCodeSender(appid, appKey);
        SmsVoiceVerifyCodeSenderResult smsVoiceVerifyCodeSenderResult = smsVoiceVerifyCodeSender.send("86",phoneNumber, msg, 2, "");
        System.out.println(smsVoiceVerifyCodeSenderResult);
        return smsVoiceVerifyCodeSenderResult;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 推送语音通知至单人
     * @param msg 通知内容
     * @param phoneNumber 手机号码
     */
    public static SmsVoicePromptSenderResult  pushVoicePromptToSingle(String msg, String  phoneNumber) {
        try {
        SmsVoicePromptSender smsVoicePromtSender = new SmsVoicePromptSender(appid, appKey);
        SmsVoicePromptSenderResult smsSingleVoiceSenderResult = smsVoicePromtSender.send("86", phoneNumber, 2, 2,msg, "");
        System.out.println(smsSingleVoiceSenderResult);
        return smsSingleVoiceSenderResult;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
